package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class MyAspect {

    @Pointcut("execution(* com.itheima.service.impl.*.*(..))")
    private void pt(){}
    @Before("pt()")
    public void before(JoinPoint joinPoint){
        System.out.println("前置通知");
        Object target = joinPoint.getTarget();
        log.info("获取目标对象:{}",target);
        String name = target.getClass().getName();
        log.info("获取目标类名称:{}",name);
        String methodName = joinPoint.getSignature().getName();
        log.info("获取目标方法名称:{}",methodName);
        Object[] args = joinPoint.getArgs();
        log.info("获取目标方法参数:{}",args);

    }
    @Around("pt()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕前通知");
        Object result = joinPoint.proceed();
        System.out.println("环绕后通知");
        return result;
    }
    @AfterReturning("pt()")
    public void afterReturning(){
        System.out.println("后置通知");
    }
    @AfterThrowing("pt()")
    public void afterThrowing(){
        System.out.println("异常通知");
    }
    @After("pt()")
    public void after(){
        System.out.println("最终通知");
    }
}
